﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using PRET.ReportDataDefine.UIData;
using PRET.ReportControlLib.ServiceReference;

namespace PRET.ReportControlLib.ReportView
{
    public partial class ProLineStandbyReportView : UserControl
    {
        private PRETWebServiceClient adapter = null;

        public ProLineStandbyReportView()
        {
            InitializeComponent();
            adapter = new PRETWebServiceClient();
        }

        private void setYearPanelSim1_showReportEvent(object sender, Controls.ShowProLineStandbyEventArgs args)
        {
            try
            {
                this.setYearPanelSim.EnableControls(false);
                if (this.adapter == null)
                {
                    MessageBox.Show("ProLineStandbyReportView没有初始化Server Adapter!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.reportViewer.LocalReport.DataSources.Clear(); //clear report
                // 从后台获取高低柜状态列表
                ProductionLineStandby[] dataList = this.adapter.GetProductionLineStandby(args.StartYear);
                if (dataList != null && dataList.Length > 0)
                {
                    Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("ProductionLineStandbyDS"); // set the datasource
                    this.reportViewer.LocalReport.DataSources.Add(dataset);
                    dataset.Value = dataList.ToList<ProductionLineStandby>();
                }
                this.reportViewer.LocalReport.Refresh();
                this.reportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                string msg = string.Format("ProLineStandbyReportView.setYearPanelSim1_showReportEvent() Failed: {0}.\r\nDetail: {1}", ex.Message, ex.StackTrace);
                MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            { this.setYearPanelSim.EnableControls(true); }
        }
    }
}
